package com.shy.springframework.aop.framework;

import com.shy.springframework.aop.AdvisedSupport;

/**
 * @author yzpang
 * @desc: 代理工厂类,
 * @date: 2023/2/10 15:56
 */
public class ProxyFactory {
    private AdvisedSupport advisedSupport;

    public ProxyFactory(AdvisedSupport advisedSupport) {
        this.advisedSupport = advisedSupport;
    }

    public Object getProxy(){
        return createAopProxy().getProxy();
    }

    /**
     * 判断使用JDK动态代理还是Cglib代理
     * @return
     */
    private AopProxy createAopProxy(){
        if (advisedSupport.isProxyTargetClass()){
            return new Cglib2AopProxy(advisedSupport);
        }
        return new JdkDynamicAopProxy(advisedSupport);
    }
}
